if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PreservationNoticeHistoryGetUnconfirmed]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[PreservationNoticeHistoryGetUnconfirmed]
GO

CREATE PROCEDURE dbo.[PreservationNoticeHistoryGetUnconfirmed]
(
	@RowCount int
)
AS

IF @RowCount > 0 SET ROWCOUNT @RowCount

SELECT
	PreservationNoticeHistoryID,
	SiteID,
	PreservationNoticeID,
	EventType,
	PreservationNoticeName,
	DateEmailMessageCreated,
	DateEmailMessageSent,
	DateAcknowledged,
	FromAddress,
	MessageSubject, 
	MessageBody,
	Identifier,
	InterviewDate,
	CustodianID,
	CustodianLastName,
	CustodianFirstName,
	HasAttachments,
	CustodianEmail,
	VerificationTries
FROM 
	PreservationNoticeHistory

WHERE
	NewSiteID IS NULL
	AND
	(DateEmailMessageSent IS NULL) AND (VerificationTries < 25)
	--AND
	--PreservationNoticeHistoryID NOT IN (SELECT PreservationNoticeHistoryID FROM inetlog)
GO

